package com.yunhe.abnormal.service.base.impl;

import com.yunhe.abnormal.domain.base.AlarmCalcType;
import com.yunhe.abnormal.mapper.base.AlarmCalcTypeMapper;
import com.yunhe.common.model.base.AlarmCalcTypeDTO;
import com.yunhe.abnormal.repository.base.AlarmCalcTypeRepository;
import com.yunhe.abnormal.service.base.AlarmCalcTypeService;
import com.yunhe.common.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 异常判断类型Service
 * @author liuronglei
 */
@Service
public class AlarmCalcTypeServiceImpl implements AlarmCalcTypeService {
    @Autowired
    private AlarmCalcTypeRepository alarmCalcTypeRepository;
    @Autowired
    private AlarmCalcTypeMapper alarmCalcTypeMapper;

    /**
     * 根据ID获得异常判断类型对象
     * @param id 状态ID
     */
    public AlarmCalcTypeDTO findById(Long id) {
        AlarmCalcType result = alarmCalcTypeRepository.findById(id).orElse(null);
        return alarmCalcTypeMapper.to(result);
    }

    /**
     * 根据编号获得异常判断类型对象
     * @param name 编号
     */
    public AlarmCalcTypeDTO findByName(String name) {
        AlarmCalcType result = alarmCalcTypeRepository.findByName(name);
        return alarmCalcTypeMapper.to(result);
    }

    /**
     * 获得全部异常判断类型对象
     */
    public Iterable<AlarmCalcTypeDTO> findAll() {
        List<AlarmCalcType> results = (List<AlarmCalcType>) alarmCalcTypeRepository.findAll(QueryUtil.defaultSort());
        return alarmCalcTypeMapper.to(results);
    }

}
